package com.hjqjl.module_choice.ui;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

import androidx.appcompat.app.AlertDialog;

import com.blankj.utilcode.util.ToastUtils;
import com.hjqjl.module_choice.R;
import com.hjqjl.module_choice.databinding.ChoiceActivityDialogstylesBinding;
import com.hjqjl.module_choice.widget.dialogfragment.DialogAlertFragment;
import com.hjqjl.module_choice.widget.dialogfragment.DialogBottomFragment;
import com.hjqjl.module_choice.widget.dialogfragment.DialogCustomFragment;
import com.hjqjl.module_choice.widget.dialogfragment.DialogLoadingFragment;
import com.hjqjl.module_choice.widget.dialogfragment.DialogTopFragment;
import com.hjqjl.whapplib.base.BaseActivity;
import com.hjqjl.whapplib.utils.dialog.DialogUtil;

public class DialogStylesActivity extends BaseActivity<ChoiceActivityDialogstylesBinding> {
    public static void start(Context context) {
        Intent intent = new Intent(context, DialogStylesActivity.class);
        context.startActivity(intent);
    }

    @Override
    public void initData() {
        setTitle("Dialog");
    }

    @Override
    public void initListener() {
        pVBinding.choiceBtnDialogStylesTopdialog.setOnClickListener(v -> {
            DialogTopFragment dialogTopFragment = DialogTopFragment.newInstance();
            dialogTopFragment.show(getSupportFragmentManager(), "topDialog");
        });

        pVBinding.choiceBtnDialogStylesCustomdialog.setOnClickListener(v -> {
            DialogCustomFragment dialogCustomFragment = DialogCustomFragment.newInstance
                    ("我是title", "我是内容--我是自定义的DialogFragment"
                            , dialog -> {
                                ToastUtils.showShort("我是内容--我是自定义的DialogFragment");
                                dialog.dismiss();
                            });
            dialogCustomFragment.show(getSupportFragmentManager(), "customDialog");
        });

        pVBinding.choiceBtnDialogStylesAlert.setOnClickListener(v -> {
            DialogAlertFragment alertDialogFragment = DialogAlertFragment.newInstance
                    ("我是title", "我是内容--MyAlertDialogFragment", "确定", "取消"
                            , (dialog, which) -> ToastUtils.showShort("我是内容--MyAlertDialogFragment")
                            , null);
            alertDialogFragment.show(getSupportFragmentManager(), "alertDialog");
        });

        pVBinding.choiceBtnDialogStylesDialogLoading.setOnClickListener(v -> {
            DialogLoadingFragment dialogLoadingFragment = DialogLoadingFragment.newInstance("加载中...");
            dialogLoadingFragment.show(getSupportFragmentManager(), "DialogLoading");
        });

        pVBinding.choiceBtnDialogStylesBottomdialog.setOnClickListener(v -> {
            DialogBottomFragment dialogBottomFragment = DialogBottomFragment.newInstance();
            dialogBottomFragment.show(getSupportFragmentManager(), "BottomDialog");
        });

        pVBinding.choiceBtnDialogStylesAlertDialog.setOnClickListener(v -> {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("标题Title");
            builder.setMessage("Message这是一个普通对话框");
            builder.setIcon(R.mipmap.choice_ic_launcher);
            builder.setCancelable(true);            //点击对话框以外的区域是否让对话框消失
            builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            AlertDialog dialog = builder.create();//创建AlertDialog对象
            dialog.show();
        });
        pVBinding.choiceBtnDialogStylesAlertDialog2.setOnClickListener(v -> {
            DialogUtil.showMyDialog(this, "我是内容啦啦啦啦", "确定", "取消"
                    , new DialogUtil.OnClickListener() {
                        @Override
                        public void onClick(AlertDialog dialog) {
                            ToastUtils.showShort("确定的");
                            dialog.dismiss();
                        }
                    }, new DialogUtil.OnClickListener() {
                        @Override
                        public void onClick(AlertDialog dialog) {
                            ToastUtils.showShort("取消的");
                            dialog.dismiss();
                        }
                    });
        });
    }
}
